package start.rabbitmq;

import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
@RabbitListener(queues = "DeadTestTopicQueue")//监听的队列名称 TestTopicQueue
public class RabbitConsumer02 {

    @RabbitHandler
    @SneakyThrows
    public void process(Map testMessage, Message message, Channel channel) {
        log.info("死信消息队列触发" + testMessage);
        //消费成功，确认消息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }

    @RabbitHandler
    @SneakyThrows
    public void process(String testMessage) {
        Thread.sleep(1*100);
        log.info("TopicReceiver消费者收到String消息  : " + testMessage.toString());
    }

    @RabbitHandler
    @SneakyThrows
    public void process(Integer testMessage) {
        Thread.sleep(1*100);
        log.info("TopicReceiver消费者收到Integer消息  : " + testMessage.toString());
    }

}